import BaseRApi from '@/framework/infra/base/BaseRApi'
import ApiAdaptor from "@/framework/infra/base/ApiAdaptor";
import request from "@/utils/request";

export default class BaseMctApi extends BaseRApi {
  constructor(module, domainClz = null) {
    super(module)
    this.domainClz = domainClz
  }

  list(params) {
    return this.get('/list', params).then(data => {
      if (!this.domainClz) {
        return data
      }
      // eslint-disable-next-line new-cap
      return ApiAdaptor.rowsAdaptor(data, row => new this.domainClz(row))
    })
  }

  page(params) {
    return this.get('/page', params).then(data => {
      if (!this.domainClz) {
        return data
      }
      // eslint-disable-next-line new-cap
      return ApiAdaptor.pageAdaptor(data, row => new this.domainClz(row))
    })
  }

  // 详情接口方法
  detail(id) {
    return this.get('detail', {id}).then(data => {
      if (!this.domainClz) {
        return data
      }
      // eslint-disable-next-line new-cap
      return new this.domainClz(data)
    })
  }

  create(data) {
    return this.post('create', data)
  }

  update(data) {
    return this.post('update', data)
  }

  remove(id) {
    return this.post('remove', {id})
  }
}
